<HTML>
<HEAD>
<TITLE>[Chapter 1] 1.4 Containers</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 14:21:37 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 1<br>Abstract Window Toolkit Overview</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch01_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JAWT-CH-1-SECT-4">1.4 Containers</A></h2>

<P CLASS=para>
<A NAME="CH01.CONT"></A>A <tt CLASS=literal>Container</tt> is a type of component 
that provides a rectangular area within which other components can be organized 
by a <tt CLASS=literal>LayoutManager</tt>. Because 
<tt CLASS=literal>Container</tt> is a subclass of 
<tt CLASS=literal>Component</tt>, a <tt CLASS=literal>Container</tt> 
can go inside another <tt CLASS=literal>Container</tt>, 
which can go inside another <tt CLASS=literal>Container</tt>, 
and so on, like Russian nesting dolls. Subclassing <tt CLASS=literal>Container</tt> 
allows you to encapsulate code for the components within it. This allows 
you to create reusable higher-level objects easily. <A HREF="ch01_04.htm#JAWT-CH-1-FIG-15">Figure 1.15</A> 
shows the components in a layout built from several nested containers.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-1-FIG-15">Figure 1.15: Components within containers</A></h4>


<p>
<img align=middle src="./figs/jawt0116.gif" alt="[Graphic: Figure 1-15]" width=453 height=214 border=0>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-1-SECT-4.1">Panels</A></h3>

<P CLASS=para>
A <tt CLASS=literal>Panel</tt> is the basic building 
block of an applet. It provides a container with no special features. The 
default layout for a <tt CLASS=literal>Panel</tt> 
is <tt CLASS=literal>FlowLayout</tt>. The details 
of <tt CLASS=literal>Panel</tt> are discussed in 
<A HREF="ch06_02.htm#JAWT-CH-6-SECT-2">Panel</A>. 
<A HREF="ch01_04.htm#JAWT-CH-1-FIG-16">Figure 1.16</A> shows an applet that contains 
panels within panels within panels. 

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-1-FIG-16">Figure 1.16: A multilevel panel</A></h4>


<p>
<img align=middle src="./figs/jawt0117.gif" alt="[Graphic: Figure 1-16]" width=410 height=175 border=0>

</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-1-SECT-4.2">Windows</A></h3>

<P CLASS=para>
A <tt CLASS=literal>Window</tt> provides a top-level 
window on the screen, with no borders or menu bar. It provides a way to 
implement pop-up messages, among other things. The default layout for a 
<tt CLASS=literal>Window</tt> is <tt CLASS=literal>BorderLayout</tt>. 
<A HREF="ch06_04.htm#JAWT-CH-6-SECT-4">Window</A> explores the <tt CLASS=literal>Window</tt> 
class in greater detail. <A HREF="ch01_04.htm#JAWT-CH-1-FIG-17">Figure 1.17</A> shows a pop-up 
message using a <tt CLASS=literal>Window</tt> in Microsoft 
Windows and Motif. 

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-1-FIG-17">Figure 1.17: Pop-up windows</A></h4>


<p>
<img align=middle src="./figs/jawt0118.gif" alt="[Graphic: Figure 1-17]" width=453 height=184 border=0>

</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-1-SECT-4.3">Frames</A></h3>

<P CLASS=para>
A <tt CLASS=literal>Frame</tt> is a <tt CLASS=literal>Window</tt> 
with all the window manager's adornments (window title, borders, 
window minimize/maximize/close functionality) added. It may 
also include a menu bar. Since <tt CLASS=literal>Frame</tt> 
subclasses <tt CLASS=literal>Window</tt>, its default 
layout is <tt CLASS=literal>BorderLayout</tt>. <tt CLASS=literal>Frame</tt> 
provides the basic building block for screen-oriented applications. <tt CLASS=literal>Frame</tt> 
allows you to change the mouse cursor, set an icon image, and have menus. 
All the details of <tt CLASS=literal>Frame</tt> are 
discussed in <A HREF="ch06_05.htm#JAWT-CH-6-SECT-5">Frames</A>. 
<A HREF="ch01_04.htm#JAWT-CH-1-FIG-18">Figure 1.18</A> shows an example 
<tt CLASS=literal>Frame</tt>. 

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-1-FIG-18">Figure 1.18: A frame</A></h4>


<p>
<img align=middle src="./figs/jawt0119.gif" alt="[Graphic: Figure 1-18]" width=242 height=243 border=0>

</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-1-SECT-4.4">Dialog and FileDialog</A></h3>

<P CLASS=para>
A <tt CLASS=literal>Dialog</tt> is a <tt CLASS=literal>Window</tt> 
that accepts input from the user. <tt CLASS=literal>BorderLayout</tt> is the default layout of <tt CLASS=literal>Dialog</tt>  
because it subclasses <tt CLASS=literal>Window</tt>. 
A <tt CLASS=literal>Dialog</tt> is a pop-up used for 
user interaction; it can be modal to prevent the user from doing anything 
with the application before responding. A <tt CLASS=literal>FileDialog</tt> 
provides a prebuilt <tt CLASS=literal>Dialog</tt> 
box that interacts with the filesystem. It implements the Open/Save 
dialog provided by the native windowing system. You will primarily use 
<tt CLASS=literal>FileDialog</tt> with applications 
since there is no guarantee that an applet can interact with the local 
filesystem. (Netscape Navigator will throw an exception if you try to 
use it.) The details of <tt CLASS=literal>Dialog</tt> 
are revealed in <A HREF="ch06_06.htm#JAWT-CH-6-SECT-6">Dialogs</A>, 
while <tt CLASS=literal>FileDialog</tt> 
is discussed in <A HREF="ch06_07.htm#JAWT-CH-6-SECT-7">FileDialog</A>. 
<A HREF="ch01_04.htm#JAWT-CH-1-FIG-19">Figure 1.19</A> shows sample <tt CLASS=literal>Dialog</tt> 
and <tt CLASS=literal>FileDialog</tt> boxes. 

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-1-FIG-19">Figure 1.19: Examples of Dialog and FileDialog boxes</A></h4>


<p>
<img align=middle src="./figs/jawt0120.gif" alt="[Graphic: Figure 1-19]" width=453 height=403 border=0>

</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-1-SECT-4.5">ScrollPane</A></h3>

<P CLASS=para>
Java 1.1 introduces the <tt CLASS=literal>ScrollPane</tt> 
container. In version 1.0, if you want to have a scrolling area (for example, 
to display an image that won't fit onto the screen), you create a 
panel using <tt CLASS=literal>BorderLayout</tt> that 
contains scrollbars on the right and bottom, and display part of the image 
in the rest of the screen. When the user scrolls, you capture the event, 
figure out what part of the image to display, and update the screen accordingly. 
Although this works, its performance is poor, and it's inconvenient. 
With version 1.1 of Java, you can tell the <tt CLASS=literal>ScrollPane</tt> 
what needs to scroll; it creates the scrollbars and handles all the events 
automatically. <A HREF="ch11_04.htm#JAWT-CH-11-SECT-4">ScrollPane</A> 
covers the <tt CLASS=literal>ScrollPane</tt>; 
<A HREF="ch01_04.htm#JAWT-CH-1-FIG-20">Figure 1.20</A> shows a <tt CLASS=literal>ScrollPane</tt>. 
<A HREF="ch11_01.htm">Chapter 11, <i>Scrolling</i></A>, covers the <tt CLASS=literal>Adjustable</tt> 
interface that <tt CLASS=literal>Scrollbar</tt> implements 
and <tt CLASS=literal>ScrollPane</tt> utilizes. 

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-1-FIG-20">Figure 1.20: A ScrollPane</A></h4>


<p>
<img align=middle src="./figs/jawt0121.gif" alt="[Graphic: Figure 1-20]" width=188 height=236 border=0>

</DIV>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch01_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Layouts</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>And the Rest</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
